﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Extensions;

public static class DbContextExtensions
{
    public static T GetDbContext<T>(this IServiceProvider serviceProvider) where T : class
    {
        using var scope = serviceProvider.CreateScope();
        var scopedServiceProvider = scope.ServiceProvider;
        return scopedServiceProvider.GetRequiredService<T>();
    }
}
